package com.ruoyi.web.controller.mall.goodsTag.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.goodsTag.domain.GoodsTag;
import com.ruoyi.web.controller.mall.goodsTag.service.IGoodsTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品标签Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@RestController
@RequestMapping("/mall/goodsTag")
public class GoodsTagController extends BaseController
{
    @Autowired
    private IGoodsTagService goodsTagService;

    /**
     * 查询商品标签列表
     */
//    @RequiresPermissions("mall:goodsTag:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody GoodsTag goodsTag)
    {
        startPage();
        List<GoodsTag> list = goodsTagService.selectGoodsTagList(goodsTag);
        return getDataTable(list);
    }

    /**
     * 获取商品标签详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(goodsTagService.selectGoodsTagById(id));
    }

    /**
     * 导出商品标签列表
     */
    @Log(title = "商品标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(@RequestBody GoodsTag goodsTag)
    {
        List<GoodsTag> list = goodsTagService.selectGoodsTagList(goodsTag);
        ExcelUtil<GoodsTag> util = new ExcelUtil<GoodsTag>(GoodsTag.class);
        return util.exportExcel(list, "goodsTag");
    }

    /**
     * 新增保存商品标签
     */
    @Log(title = "商品标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody GoodsTag goodsTag)
    {
        goodsTag.setGmtCreate(DateUtils.getNowDate());
        goodsTag.setDelFlag(0);
        goodsTag.setId(StringUtils.get32UUID());
        return toAjax(goodsTagService.insertGoodsTag(goodsTag));
    }

    /**
     * 修改保存商品标签
     */
    @Log(title = "商品标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult editSave(@RequestBody GoodsTag goodsTag)
    {
        goodsTag.setGmtModified(DateUtils.getNowDate());
        return toAjax(goodsTagService.updateGoodsTag(goodsTag));
    }

    /**
     * 删除商品标签
     */
    @Log(title = "商品标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    public AjaxResult remove(@RequestBody GoodsTag goodsTag)
    {
        return toAjax(goodsTagService.deleteGoodsTagById(goodsTag.getId()));
    }
}
